
/*
 *  spa.search.js
 *  폼 입력을 바탕으로 데이터베이스에게 쿼리요청을 보내는 모듈
 */

spa.search = (function() {
/*-----------------------Module Variable Start----------------------*/
  var configMap = {
    main_html : String()
      + '<h1>상세 검색</h1>'
      + '<p>Title : <input type="text" class="spa-search-title_input" /></p>'
      + '<p>Date : '
        + '<input type="text" class="start_year spa-search-dateinput" />'
        + '<input type="text" class="start_month spa-search-dateinput" />'
        + '<input type="text" class="start_day spa-search-dateinput" />'
        + '~ '
        + '<input type="text" class="end_year spa-search-dateinput" />'
        + '<input type="text" class="end_month spa-search-dateinput" />'
        + '<input type="text" class="end_day spa-search-dateinput" />'
      + '</p>'
      + '<p>Category : <select class="cmb_category">'
        + '<option value="">전체</option>'
        + '<option value="1">정치</option>'
        + '<option value="2">사회</option>'
        + '<option value="3">경제</option>'
        + '<option value="4">국제</option>'
        + '<option value="5">의학과학</option>'
        + '<option value="6">문화연예</option>'
        + '<option value="7">스포츠</option>'
      + '</select></p>'
      + '<div class="btn_search_attr"><img src="images/magnifier.svg" /></div>'

  },
  stateMap = {
    $container : null
  },
  jqueryMap = {},
  initModule, setJqueryMap, onClickSearchAttrButton;
/*-----------------------Module Variable End------------------------*/
    
/*-----------------------Utility Method Start-----------------------*/
/*-----------------------Utility Method End-------------------------*/

/*-----------------------DOM Method Start---------------------------*/
  // /setJqueryMap/ Start
  setJqueryMap = function() {
    var $container = stateMap.$container;
    jqueryMap = {
      $container : $container
    };
  };
  // /setJqueryMap/ End
/*-----------------------DOM Method End-----------------------------*/
    
/*-----------------------Event Handler Start------------------------*/
  onClickSearchAttrButton = function( e ) {
    var title, start_date, end_date, category;
    title = $(".spa-search-title_input").val();
    category = $(".cmb_category").val();
    start_date = $(".start_year").val() + "/" + $(".start_month").val() + "/" + $(".start_day").val();
    end_date = $(".end_year").val() + "/" + $(".end_month").val() + "/" + $(".end_day").val();
    
    spa.model.article.getList(1, category, title, start_date, end_date);
  };
/*-----------------------Event Handler End--------------------------*/

/*-----------------------Public Method Start------------------------*/
  // /initModule/ Start
  initModule = function($container) {
    stateMap.$container = $container;
    $container.html(configMap.main_html);
    setJqueryMap();

    $(".btn_search_attr").on("click", onClickSearchAttrButton);
  };
  // /initModule/ End
/*----i------------------Public Method End--------------------------*/
  // Return public function
  return {initModule : initModule};
}());
